package cn.iocoder.yudao.module.famous.doctor.controller.app.FamNotice;

import cn.iocoder.yudao.module.famous.doctor.controller.app.famNoticeClose.vo.AppFamNoticeCloseBaseVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.app.FamNotice.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.FamNotice.FamNoticeDO;
import cn.iocoder.yudao.module.famous.doctor.convert.FamNotice.FamNoticeConvert;
import cn.iocoder.yudao.module.famous.doctor.service.FamNotice.FamNoticeService;

@Tag(name = "用户 APP - 公告")
@RestController
@RequestMapping("/famous.doctor/fam-notice")
@Validated
public class AppFamNoticeController {

    @Resource
    private FamNoticeService famNoticeService;


    @GetMapping("/getByClientType")
    @Operation(summary = "通过客户端类型获取最新一条公告")
    @Parameter(name = "clientType", description = "编号，不传默认用户端", required = false, example = "1")
    @Parameter(name = "userId", description = "用户id，排除已关闭的公告", required = false, example = "1")
    public CommonResult<AppFamNoticeRespVO> getFamNoticeByClientType(
            @RequestParam(value = "clientType",required = false) Byte clientType,
            @RequestParam(value = "userId",required = false) Long userId) {
        FamNoticeDO famNotice = famNoticeService.getFamNoticeByClientType(clientType,userId);
        return success(FamNoticeConvert.INSTANCE.convertApp(famNotice));
    }

    /**
     * 用户关闭公告，不再提醒
     * */
    @PostMapping("/closeNotice")
    @Operation(summary = "关闭公告")
    public CommonResult<Boolean> closeNotice(@Validated @RequestBody AppFamNoticeCloseBaseVO appFamNoticeCloseBaseVO) {
        famNoticeService.closeNotice(appFamNoticeCloseBaseVO);
        return success(true);
    }

}
